package com.gxar.quick.ar.server.base.model.works.mapper;

import com.gxar.quick.ar.server.base.model.works.vo.request.WorksDraftCreateRequest;
import com.gxar.quick.ar.server.base.model.works.vo.request.WorksPreviewCreateRequest;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftCreateResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftInfoResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftListResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksDraftUpdateResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksPreviewCreateResponse;
import com.gxar.quick.ar.server.base.model.works.vo.response.WorksPreviewInfoResponse;
import com.gxar.quick.ar.server.db.model.WorksDraftEntity;
import com.gxar.quick.ar.server.db.model.WorksPreviewEntity;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 作品草稿转换工具
 *
 * @author Linsy
 * @version 1.0
 * @created 2023/11/8 10:45 AM
 */
@Mapper
public interface WorksPreviewMapStruct {
    WorksPreviewMapStruct INSTANCE = Mappers.getMapper(WorksPreviewMapStruct.class);

    /**
     * 作品创建转换实体
     *
     * @param request 请求
     * @return 响应
     */
    @Mapping(target = "templateId", expression = "java(request.getTemplateId() != null ? Long.parseLong(request.getTemplateId()) : null)")
    WorksPreviewEntity createToEntity(WorksPreviewCreateRequest request);

    /**
     * 作品预览转创建响应
     *
     * @param entity 实体
     * @return 响应
     */
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workPreviewId", expression = "java(String.valueOf(entity.getId()))")
    WorksPreviewCreateResponse entityToCreateResponse(WorksPreviewEntity entity);

    /**
     * 作品预览转作品信息
     *
     * @param entity 实体
     * @return 作品信息
     */
    @Mapping(target = "templateId", expression = "java(entity.getTemplateId() != null ? String.valueOf(entity.getTemplateId()) : null)")
    @Mapping(target = "workPreviewId", expression = "java(String.valueOf(entity.getId()))")
    @Mapping(target = "userId", expression = "java(String.valueOf(entity.getUserId()))")
    WorksPreviewInfoResponse entityToInfoResponse(WorksPreviewEntity entity);

}
